import request from '@/utils/request.js'

// 获取最后一条聊天消息
export function getLastMsg(uid, fid) {
  return request({
    url: `/message/lastMsg?uid=${uid}&fid=${fid}`
  })
}

// 获取消息未读数
export function getUnReadCount(uid, fid) {
  return request({
    url: `/message/unread?uid=${uid}&fid=${fid}`
  })
}

// 获取聊天消息
export function getMsg(uid, fid, page_num) {
  return request({
    url: `/message/msgs?uid=${uid}&fid=${fid}&page_num=${page_num}`
  })
}

// 更新消息状态为已读
export function udpateMsgState(uid, fid) {
  return request({
    url: `/message/upstate?uid=${uid}&fid=${fid}`,
    method: 'put'
  })
}

// 插入聊天消息
export function insertMsg(data) {
  return request({
    url: '/message/insert',
    method: 'post',
    data: data
  })
}

// 查找是否有未读消息
export function findIsHadUnReadMsg(uid) {
  return request({
    url: `/message/isunread?uid=${uid}`
  })
}